// import { Forbbiden, } from "@/core/HttpException";
import { Middleware, IMiddleware } from "@midwayjs/core";
import { NextFunction, Context } from "@midwayjs/koa";

@Middleware()
export class HaspermiMiddleware implements IMiddleware<Context, NextFunction> {

    resolve() {
        return async (ctx: Context, next: NextFunction) => {
            // let userInfo = typeof ctx.userInfo === "string" ? JSON.parse(ctx.userInfo) : {permissions:["/api/v1/message/getMessage","/api/v1/4m/m"]};
            
            // if (userInfo.permissions.findIndex(v => v == ctx.path) !== -1) {
                await next()
            // } else {
            //     throw new Forbbiden("无权限");
            // }
        }
    }

    ignore(ctx: Context): boolean {
        return ctx.path === "/" || ctx.path === "/login"
    }

    static getName(): string {
        return "haspermi"
    }
}